﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ComplexDataStructures.aspx.cs"
    Inherits="Demo.Demos.ComplexDataStructures.ComplexDataStructures" MasterPageFile="~/Example.Master" %>

<asp:Content ID="Content4" runat="server" ContentPlaceHolderID="MainContent">
    <p>
        Left side of this demo is interactive illustration of some imaginary organizational
        hierarchy. You can freely add, remove or edit hierarchy information.</p>
    <p>
       Bottom of the page contains listings of top <i>n</i> most powerful people in hierarchy.</p>

    <p>Person's power is detemined by some complex law. You can modify <b>power factor</b> calculation formula directly in <i>PersonViewModel</i>, <i>PowerFactor</i> property. Current
    power factor depends on following factors:</p>
        <ul>
            <li>Hierarchy position - higher the person is in hierarchy, the more power it has <img alt="" src="img/eq1.png" width="150" /></i></li>
            <li>Number of friends - more friends person has, the more social power it has</li>
            <li>Friend's position in hierarchy - it's different situation if person has a friend in first level of hierarchy or some other level (<i>hierarchy power * result friend factor</i>)</li>
            <li>Mutual friendship - if person consideres some other person as a his/her's friend, and if it's not mutual, he/she actually looses his/her's power factor.
            That idea can be represented with the following table</li>
            </ul>

            <table class="table table-bordered d-cds-table" style="width:700px;">
            <tr>
                <td><b>ResultFriendFactor</b></td>
                <td>A > B a friend</td>
                <td>A > B not a friend</td>
            </tr>
            <tr>
                <td>B > A a friend</td>
                <td>FriendFactor</td>
                <td>+OneSideFriendFactor</td>
            </tr>
            <tr>
                <td>B > A not a friend</td>
                <td>-OneSideFriendFactor</td>
                <td>0</td>
            </tr>
            </table>
            <p class="car-desc">Table 1. - Contribution constant to person A's power factor (<i>result friend factor</i>)</p>

            <p>The final equation for calculating power factor is presented here</p>
            <p>
            <img src="img/eqn5193.png" alt="0" width="800" border="0" />
</p>
            <p>Although this is not tipical business case scenario, this example demonstrates how your data model can be any complex data graph and it won't make any difference. 
            You'll still be able to edit and map the model as naturally as possible while conforming to separation of concerns principle.</p>
            <p>It's almost incredible that the entire logic is contained in the files listed below. Imagine how much lines you would need to write for the same behaviour without
            this framework using regular ASP.NET.</p>

            <blockquote class="quote">
            <p><b>Hints</b></p>
            <ul>
            <li>You can easily detect conspiracies against the boss by increasing the <i>Friend factor</i>. (Try setting the <i>Friend factor</i> to 10.00 and see if you can
            spot conspiracies.)
            </li>
            <li>You can also detect superstars by increasing <i>One side friend factor</i>. (Supersars have no friends but everybody want to be their friends, try setting this
            parameter to 10.00 and see if you can spot a superstar.)</li>
            </ul>
            </blockquote>
        <hr />
    <asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
        <ContentTemplate>
            <d:ComplexDataStructuresDataContext runat="server">
                <div class="row-fluid">
                    <div class="span3 demo-tree">
                        <p><b>Hierarchy</b></p>
                        <cwf:DataContextOnPath runat="server" DataPath="RootPerson">
                            <d:TreeViewNodeLoader runat="server" />
                        </cwf:DataContextOnPath>
                    </div>
                    <div class="span9">
                        <div class="d-cds-editperson">
                        <cwf:IfElsePanel runat="server" ConditionDataPath="IsPersonSelected">
                            <IfTemplate>
                                <div class="d-cds form-horizontal">
                                    <cwf:IfElsePanel runat="server" OnCondition="Calculate_CanDelete">
                                    <IfTemplate>
                                    <asp:LinkButton runat="server" CssClass="d-cds-delete" OnClick="Click_Delete">Delete</asp:LinkButton>
                                    </IfTemplate>
                                    </cwf:IfElsePanel>
                                    <div class="avatar-area">
                                        <img alt="" src="<%# GetImageUrl(Container) %>" width="90" height="90" class="avatar-image" border="0" />
                                        <cwfj:fileuploadeditor runat="server" datapath="SelectedPerson.CustomAvatarPicture"
                                            maxnumberoffiles="3" allowedextensions=".bpm; .jpg; .jpeg; .gif; .png" />
                                    </div>
                                    <fieldset>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput">
                                                Level</label>
                                            <div class="controls">
                                                <cwf:ModelValue runat="server" DataPath="SelectedPerson.HierarchyLevel" />
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput">
                                                Power factor</label>
                                            <div class="controls">
                                                <b><cwf:ModelValue runat="server" DataPath="SelectedPerson.PowerFactor" /></b>
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput">
                                                Name</label>
                                            <div class="controls">
                                                <cwfj:simpleeditor runat="server" datapath="SelectedPerson.Name" maxlength="20" canbenull="false" AutoPostBack="true" />
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput">
                                                Friends</label>
                                            <div class="controls">
                                            <table class="table table-bordered table-striped d-cds-table">
                                                <tr>
                                                    <th></th>
                                                    <th>Friend name</th>
                                                    <th>Order</th>
                                                    <th>Remove</th>
                                                </tr>
                                                <cwf:CollectionEditor runat="server" DataPath="SelectedPerson.DisplayFriends">
                                                    <ItemTemplate>
                                                    <tr>
                                                    <td><%# Container.DataItemIndex + 1 %></td>
                                                    <td>
                                                        <asp:LinkButton runat="server" OnClick="Click_GoToFriend" >
                                                        <cwf:ModelValue runat="server" DataPath="Friend.DisplayName" />
                                                        </asp:LinkButton> </td>
                                                        <td><cwfj:ListEditor CssClass="d-cds-order" runat="server" DataPath="FriendOrder" AutoPostBack="true" /></td>
                                                        <td><asp:LinkButton runat="server" OnClick="Click_RemoveFriend" Text="Remove" /></td>
                                                    </tr>
                                                    </ItemTemplate>
                                                </cwf:CollectionEditor>
                                                </table>
                                                <div>
                                                Add friend <cwfj:ListEditor runat="server" DataPath="SelectedPerson.AddNewFriendPickerDropDown" AutoPostBack="true"/>
                                                </div>
                                            </div>
                                        </div>
                                    </fieldset>
                                </div>
                            </IfTemplate>
                        </cwf:IfElsePanel>
                        </div>
                    </div>
                </div>
                <hr />
                <p><b>Modify constants</b></p>
                <table class="table table-bordered table-striped d-cds-table">
                    <tr>
                        <th>Coefficient</th>
                        <th>Value</th>
                    </tr>
                    <tr>
                        <td>Level dampening factor</td>
                        <td><cwfj:SimpleEditor runat="server" DataPath="LevelFactor" AutoPostback="true" /></td>
                    </tr>
                    <tr>
                        <td>Friend factor</td>
                        <td><cwfj:SimpleEditor runat="server" DataPath="FriendFactor" AutoPostback="true" /></td>
                    </tr>
                    <tr>
                        <td>One side friend factor</td>
                        <td><cwfj:SimpleEditor runat="server" DataPath="OneSideFriendFactor" AutoPostback="true" /></td>
                    </tr>
                </table>

                <hr />
                
                    Top
                    <cwfj:simpleeditor runat="Server" datapath="ShowTop" autopostback="true" Width="40" />
                    socially most powerfull persons.
                    <div style="height:10px"></div>
                <table class="table table-bordered table-striped d-cds-table">
                    <tr>
                        <th>
                            
                        </th>
                        <th>
                            Name
                        </th>
                        <th>
                            Power factor
                        </th>
                        <cwf:CollectionEditor runat="server" DataPath="MostPowerfulPersons">
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <%# Container.DataItemIndex + 1 %>
                                    </td>
                                    <td>
                                        <cwf:ModelValue runat="server" DataPath="Name" />
                                    </td>
                                    <td>
                                        <cwf:ModelValue runat="server" DataPath="PowerFactor" Format="{0:0.00}" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </cwf:CollectionEditor>
                    </tr>
                </table>
            </d:ComplexDataStructuresDataContext>
        </ContentTemplate>
    </asp:UpdatePanel>
        <hr />
</asp:Content>
